const Koa = require('koa');

const { ApolloServer, gql } = require('apollo-server-koa');

const usersSource = require('./src/models/user/source');

const typeDefs = require('./src/typeDefs');
const resolvers = require('./src/resolvers');

console.log(resolvers.Query);

require('./src/db');

const server = new ApolloServer({
  typeDefs,
  resolvers,
  dataSources: () => ({
    users: usersSource,
  })
});

async function start () {
  
  await server.start();

  const app = new Koa();
  server.applyMiddleware({ app });

  await new Promise(resolve => app.listen(4000, resolve));
  console.log(`Server ready at http://localhost:4000${server.graphqlPath}`)
  return { server, app };
}


start();